
/**
*一个区域和一个实体，鼠标移动进入区域后哪个实体就出现
*mc_mask,mc_btnpad
*/
package kgame5.kgui.kcomp {
import flash.display.*;
import flash.events.*;

import gs.TweenLite;

import kgame5.kutil.*;

public class SmartPane{
	
	//___________________PROPERTY___________________
	private var mc:Sprite;//自己的实体
	
	private var
		closeX:Number,closeY:Number,//处在关闭状态的时候的xy
		openX:Number,openY:Number;//处在打开状态的时候的xy
		
	private var
		MoveDur:Number=0.3;//秒，移动到达目标的时间
		
	private var isOpened:Boolean=false;//是否打开了
	//___________________METHOD______________________
	public function SmartPane(p_mc:Sprite,
				p_closeX:Number,p_closeY:Number,
				p_openX:Number,p_openY:Number,
				dur:Number=0.3){
					
		mc=p_mc;
		
		closeX=p_closeX;
		closeY=p_closeY;
		
		openX=p_openX;
		openY=p_openY;
		
		MoveDur=dur;
	
		//--
		mc.x=closeX;
		mc.y=closeY;
		isOpened=false;
		
		//--!!注意这个最开始就是显示的
		show();
		//hide();
	}
	
	public function show(){
		//T.p("smartBtnpad.show()");
		mc.visible=true;
	}
	
	public function hide(){
		//T.p("smartBtnpad.hide()");
		mc.visible=false;
		
		//不显示的时候直接放回去
		//Tween2DX.ClearTween(mc);
		TweenLite.killTweensOf(mc);
		mc.x=closeX;
		mc.y=closeY;
	}
	
	//注册鼠标滑进滑出
	public function OnLoad(){
		mc.addEventListener(MouseEvent.ROLL_OVER, mroverH);
		mc.addEventListener(MouseEvent.ROLL_OUT, mroutH);
	}
	
	//鼠标滚进
	private function mroverH(e:MouseEvent){
		openPane();
	}
	//鼠标滚出
	private function mroutH(e:MouseEvent){
		closePane();
	}
	//
	public function openPane(){
		if(isOpened){
			T.p("openPane 已经打开就不再打开");
			return;
		}
		isOpened=true;
		//Tween2DX.ClearTween(mc);
		//Tween2DX.StartMove(mc, openX, openY,MoveDur);
		
		TweenLite.killTweensOf(mc);
		TweenLite.to(mc,MoveDur,{x:openX,y:openY});
	}
	//
	public function closePane(){
		if(isOpened==false){
			T.p("closePane已经关闭就不再打开");
			return;
		}
		isOpened=false;
		
		//Tween2DX.ClearTween(mc);
		//Tween2DX.StartMove(mc, closeX, closeY,MoveDur);
		
		TweenLite.killTweensOf(mc);
		TweenLite.to(mc,MoveDur,{x:closeX,y:closeY});
	}
}//end of class
}